﻿/**
   需求文档 http://wiki.jrj.com.cn/pages/viewpage.action?pageId=95623727
   Bulid文件 工业数据-HTML.rar
 
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.TableHtmlGeterate;
namespace Web.NewProcect
{
    public partial class Default : System.Web.UI.Page
    {
        /// <summary>
        /// 近期数据
        /// </summary>
        protected string RecentDataHtml = string.Empty;
        /// <summary>
        /// 关联期货
        /// </summary>
        protected string RelateFutureIndexHtml = string.Empty;
        /// <summary>
        /// 关联行业
        /// </summary>
        protected string RelateIndustryHtml = string.Empty;
        /// <summary>
        /// 同行业个股
        /// </summary>
        protected string StocksWithSameIndustialHtml = string.Empty;

        protected App_Codes.XMLInfo pageInfo = null;

        protected string GlobalIndex = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            List<App_Codes.XMLInfo> infos = App_Codes.XMLSingletonReader.GetXMLInfos();

            #region 得到Request参数，如果不传则默认为宝山钢市

            string code = string.Empty;
            if (!string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                code = Request.QueryString["code"];
            }
            else
            {
                code = infos.First().Code;
            }


            pageInfo = infos.Where(a => a.Code.ToLower().Equals(code.ToLower())).FirstOrDefault();
            if (pageInfo == null)
            {

                log4net.LogManager.GetLogger("david").Info("传入的参数未定义，用户手动传入了参数");
                pageInfo = infos.FirstOrDefault();
            }



            this.RequestCode.Value = code.ToUpper();

            #endregion

            #region 判断是否存在多Tab或多Select，如果存在则把页面获取参数的Filter补充完整

            string _pageFilters = "";

            if (pageInfo.TabInfos != null && pageInfo.TabInfos.Count > 0)
            {
                if (!string.IsNullOrEmpty(pageInfo.TabInfos.First().Code))
                {
                    //   pageInfo.RecentDataFilter += pageInfo.TabInfos.First().Code;
                    _pageFilters = pageInfo.RecentDataFilter + pageInfo.TabInfos.First().Code;
                }
            }

            #endregion


            #region 获取查询页面的相关期货信息

            if (!string.IsNullOrEmpty(pageInfo.RelatedFuture))
            {

                string[] codes = pageInfo.RelatedFuture.Split(new char[] { ',' });

                RelateFutureIndexHtml = TableHtmlGeterate.TableBulider.BuildIndexFuturesTBody(codes);
            }
            else
            {
                RelateFutureIndexHtml = string.Empty;
            }

            #endregion



            #region 获取页面需要读取的具体字段

            string priceColumn = string.Empty;

            priceColumn = pageInfo.TabInfos.First().PriceColumn;


            #endregion


            #region 判断需要展示的页面类型,加载近期数据

            List<string> tablePrices = new List<string>();

            if (pageInfo.RecentTableType.Equals("OneKeyWordTable"))
            {
                tablePrices.Add(priceColumn);
            }
            else if (pageInfo.RecentTableType.Equals("MoreKeyWordsTable"))
            {
                string[] keywords = priceColumn.Split(new char[] { ',' });
                foreach (string s in keywords)
                {
                    if (!string.IsNullOrEmpty(s))
                    {
                        tablePrices.Add(s);
                    }
                }

            }

            RecentDataHtml = TableHtmlGeterate.TableBulider.BuildCurrentDataTBody(pageInfo.RecentDataTable, _pageFilters, pageInfo.DateColumn, pageInfo.TableColumns, tablePrices, code);
            #endregion

            #region 关联行业

            RelateIndustryHtml = TableHtmlGeterate.TableBulider.BuildRelatedIndustriesTBody(pageInfo.RelatedIndustry);//ok

            #endregion


            #region 同行业个股一览

            StocksWithSameIndustialHtml = TableHtmlGeterate.TableBulider.BuildTheSameIndustryStocksTBody(pageInfo.RelatedIndustry);//ok

            #endregion


            //  GlobalIndex = App_Codes.GlobalIndexRequest.GetGlobalIndexFromWeb();
        }
    }
}